<template>
  <div class="container">
    医生界面
    医生名称:{{userInfo.data.userName}}
    医生状态：{{userInfo.data.consultationType}}
    医生编号：{{userInfo.data.userId}}

    <div class="logout-button-container">
      <button @click="logout" class="logout-btn">退出登录</button>
    </div>

    <el-button type="text" @click="dialogFormVisible = true"></el-button>
    <el-button type="text" @click="toCircle">病友圈</el-button>

    <el-dialog title="-------------" :visible.sync="dialogFormVisible">
      <el-form :model="admissionsRequest">
        <el-form-item label="诊断结果" :label-width="formLabelWidth">
          <el-input v-model="admissionsRequest.receiveInformation" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="generateDiagnosticReport()">生成诊断报告</el-button>
      </div>
    </el-dialog>


    <el-button type="text" @click="healthrecords = true"></el-button>
    <el-dialog title="健康档案" :visible.sync="healthrecords">
      <el-descriptions v-for="item in gridData.data" title="健康档案">
        <el-descriptions-item label="患者名称">{{ item.userName}}</el-descriptions-item>
        <el-descriptions-item label="年龄">{{item.userAge}}</el-descriptions-item>
        <el-descriptions-item label="性别">{{item.userSex}}</el-descriptions-item>
        <el-descriptions-item label="身高">{{item.patientHeight}}</el-descriptions-item>
        <el-descriptions-item label="体重">{{item.patientWeight}}</el-descriptions-item>
        <el-descriptions-item label="肾功能">{{item.kidney}} </el-descriptions-item>
        <el-descriptions-item label="婚姻状况"> {{item.marry}} </el-descriptions-item>
        <el-descriptions-item label="生育状况"> {{item.allergicHistory}} </el-descriptions-item>
        <el-descriptions-item label="疾病史"> {{item.medicalHistory}} </el-descriptions-item>
      </el-descriptions>
    </el-dialog>

    <!--    搜索-->
    <el-form ref="form" :model="receiveRequest" label-width="80px">
      <el-form-item label="患者">
        <el-input v-model="receiveRequest.userName"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即搜索</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>

    <el-row>
      <el-button type="primary" @click="diagnosticManagement()">跳转诊断管理</el-button>
      <el-button type="primary" @click="no()">未诊断</el-button>
      <el-button type="primary" @click="yes()">已诊断</el-button>
      <el-button type="primary" @click="open(userId)" :disabled="userInfo.data.consultationType===1">开启问诊</el-button>
      <el-button type="primary" @click="close(userId)" :disabled="userInfo.data.consultationType===2" >关闭问诊</el-button>
    </el-row>
    <el-table
      :data="tableData.tableDatalist"
      style="width: 100%">
      <el-table-column
        prop="receiveId"
        label="序号"
        width="180">
      </el-table-column>
      <el-table-column
        prop="receiveDate"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="receivePrice"
        label="金额"
        width="180">
      </el-table-column>
      <el-table-column
        prop="userName"
        label="患者名称"
        width="180">
      </el-table-column>
      <el-table-column
        prop="userAge"
        label="年龄">
      </el-table-column>
      <el-table-column
        prop="receiveType"
        label="状态">
      </el-table-column>
      <!--      操作-->
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="admissions(scope.row.receiveId)">接诊</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="healthRecords(scope.row.receiveId)">健康档案</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）,
//例如：import 《组件名称》 from '《组件路径》,
import axios from "axios";
import res from 'autoprefixer'

export default {
  //import引入的组件需要注入到对象中才能使用"
  components: {},
  props: {},
  data() {
    //这里存放数据"

    return {
      admissionsRequest:{
        receiveId:'',
        receiveInformation:'',
      },
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      dialogFormVisible: false,
      formLabelWidth: '120px',
      consultationType:'',
      userId:'',
      gridData: [{

      }],
      healthrecords:false,
      tableData:{
        total:0,
        tableDatalist:[],
      },
      tableDatas:{
        total:0,
        tableDatalist:[],
      },
      receiveRequest:{
        userName:'',
        userPhone:'',
        pageNum:1,
        pageSize:10,
        receiveType:'',
        doctorId:2,
      },


      // 用户信息
      userInfo:{},

    }
  },
  //计算属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    toCircle(){
      this.$router.push('/community')
    },
    // 生成诊断报告
    generateDiagnosticReport(){
      console.log("aaa")
      axios.post('/api/receman/generateDiagnosticReport',this.admissionsRequest).then(res=>{
        console.log(res.data)
        this.dialogFormVisible=false
        window.location.reload()



      })

    },

    logout(){
      axios.post('/api/auth/logOut').then(
        res=>{
          if (res.data.code==200){
            this.$router.push('/')
          }
        }
      )

    },
    listreception(){
      axios.post('/api/receman/listreception',this.receiveRequest).then(res=>{
        this.tableData.tableDatalist=res.data.data.list;
        this.tableDatas.tableDatalist=res.data.data.list;
        this.tableData.tableDatalist = this.tableData.tableDatalist.filter(item => item.receiveType === 0);
        console.log(this.tableData.tableDatalist);
      })
    },
    healthRecords(receiveId){
      this.healthrecords=true
      axios.post(`/api/receman/healthRecords/${receiveId}`).then(res=>{
        console.log(res.data)
        this.gridData=res.data
      })
    },
    admissions(receiveId){
      console.log(receiveId)
      this.admissionsRequest.receiveId=receiveId;

      this.dialogFormVisible=true
    },
    onSubmit(){
      axios.post('/api/receman/listreception',this.receiveRequest).then(res=>{
        console.log(res.data.list)
        this.tableData=res.data
      })
    },
    cancel(){

      this.receiveRequest.userName=''
      this.listreception()
    },
    no(){
      console.log(" 展示未诊断的数据")
      this.tableData.tableDatalist=this.tableDatas.tableDatalist
      this.tableData.tableDatalist = this.tableData.tableDatalist.filter(item => item.receiveType === 0);
      console.log(this.tableData.tableDatalist);
      // if(this.receiveRequest.receiveType = 0){
      //
      //   this.listreception();
      // }

    },
    diagnosticManagement(){
      this.$router.push('/diagnosticManagement')
    },
    yes(){
      this.tableData.tableDatalist=this.tableDatas.tableDatalist
      this.tableData.tableDatalist = this.tableData.tableDatalist.filter(item => item.receiveType === 1);

      console.log(this.tableData.tableDatalist);
      console.log("展示 已诊断的数据")

    },
    open(userId){
      userId=this.userInfo.data.userId
      console.log(userId)
      axios.post(`/api/receman/openConsultation/${userId}`).then(res=>{
        console.log(res.data)
        this.gridData=res.data
        window.location.reload()
      })

    },
    close(userId){
      userId=this.userInfo.data.userId
      console.log(userId)
      axios.post(`/api/receman/closeConsultation/${userId}`).then(res=>{
        console.log(res.data)
        this.gridData=res.data
        window.location.reload()
      })

    },
    getUserInfo(){
      axios.post('/api/auth/userInfo').then(res=>{
        console.log(res.data)
        this.userInfo=res.data
        // this.receiveRequest.doctorId=this.userInfo.data.userId
        // console.log("---"+this.receiveRequest.doctorId)
      })
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）",
  created() {
    this.listreception();
    this.getUserInfo()
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",
  mounted() {
  },
  beforeCreate() {
  }, //生命周期 - 创建之前",
  beforeMount() {
  }, //生命周期 - 挂载之前",
  beforeUpdate() {
  }, //生命周期 - 更新之前",
  updated() {
  }, //生命周期 - 更新之后",
  beforeDestroy() {
  }, //生命周期 - 销毁之前",
  destroyed() {
  }, //生命周期 - 销毁完成",
  activated() {
  } //如果页面有keep-alive缓存功能，这个函数会触发",
};
</script>
<style scoped>
.form-center {
  display: flex;
  justify-content: center;
}

.form {
  text-align: center;
  margin: auto;
}
.container {
  position: relative; /* 使容器成为一个定位上下文 */
}

.logout-button-container {
  position: absolute;
  top: 0px; /* 根据实际情况调整顶部距离 */
  right: 10px; /* 根据实际情况调整右侧距离 */
}

.logout-btn {
  color: #42b983;
  /* 样式调整，比如颜色、大小、边框等 */
}
</style>
